﻿using System;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SNSpirit.Web.Client
{
    public class WebClientBase : WebClient, IWebClient
    {
        public WebClientBase()
        {
            this.CookieContainer = new CookieContainer();
            this.EnableCookieManage = true;
        }
        /// <summary>
        /// Enable cookie manage
        /// Default is true
        /// </summary>
        public bool EnableCookieManage { get; set; }

        protected override WebRequest GetWebRequest(Uri address)
        {
            var webrequest = base.GetWebRequest(address);
            if(this.EnableCookieManage)
                this.AttachCookieToRequest(webrequest);
            return webrequest;
        }

        #region cookie manage

        protected virtual void AttachCookieToRequest(WebRequest request)
        {

        }

        protected CookieContainer CookieContainer { get; set; }

        #endregion
    }
}
